<template>
  <div>
    <el-dialog
        :close-on-click-modal="false"
        :title="ComponentDetail.label"
        custom-class="app-event-dialog us-none"
        v-model="ShowComponentDialog"
        :width="ComponentDetail.dialogWidth"
        draggable
        overflow
        top="5vh"
    >
      <component :is="components[ComponentDetail.name]" :ref="ComponentDetail.name" @close="CloseDialog"/>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
import {ref, defineComponent, onMounted, onUnmounted} from "vue";

import {DATA_MANAGE, USER_LOGIN, EVENT_MANAGE, GLOBAL_PARAM, DEVICE_MANAGE} from './components'
//@ts-ignore
import {Emitter} from "@/utils/Emitter.js";
import {AppParams} from '@/utils/appParams'
import {System} from "@/api/SystemApi";
import {PageEnum} from "@/enums/pageEnum";

const components = {
  DATA_MANAGE, USER_LOGIN, EVENT_MANAGE, GLOBAL_PARAM, DEVICE_MANAGE
}

const ComponentDetail = ref({})
const ShowComponentDialog = ref(false)

/**
 * 内部消息统一在这里处理
 *
 * @param Component
 * @constructor
 */
const IsShowComponent = (Component: any) => {
  const EVENT = AppParams.JAVA_SCRIPT_EVENT as any;
  switch (Component.MessageBusType) {
    case EVENT.USER_LOGIN:
    case EVENT.DATA_MANAGE:
    case EVENT.DEVICE_MANAGE:
    case EVENT.GLOBAL_PARAM:
    case EVENT.EVENT_MANAGE:
      ShowComponentDialog.value = Component !== null
      if (ShowComponentDialog.value) {
        ComponentDetail.value = Component || {}
      }
      break
    case EVENT.OPEN_SYSTEM_LOGGER_FORM: // 打开系统日志
      System.OpenForm(PageEnum.BASE_LOGGER_ITEMS)
      break
  }
}

onMounted(() => {
  Emitter.on(AppParams.JAVA_SCRIPT_EVENT.POST_MESSAGE_BUS, (data: any) => IsShowComponent(data))
})

onUnmounted(() => {
  Emitter.off(AppParams.JAVA_SCRIPT_EVENT.POST_MESSAGE_BUS, IsShowComponent);
})
/**
 * func
 */
const CloseDialog = () => {
  ShowComponentDialog.value = false
}

</script>

<style scoped lang="scss">

</style>
